<template>
  <a-breadcrumb style="font-size: 18px; font-weight: bold; margin-bottom: 20px">
    <a-breadcrumb-item>平台管理员</a-breadcrumb-item>
    <a-breadcrumb-item>个人信息管理</a-breadcrumb-item>
  </a-breadcrumb>
  <a-descriptions title="User Info">
    <a-descriptions-item label="管理员ID">{{
      info[0] && info[0].m_id
    }}</a-descriptions-item>
    <a-descriptions-item label="昵称">{{
      info[0] && info[0].m_name
    }}</a-descriptions-item>
    <a-descriptions-item label="性别">{{
      info[0] && info[0].m_sex == 1 ? "男" : "女"
    }}</a-descriptions-item>
    <a-descriptions-item label="生日">{{
      info[0] && info[0].m_birth
    }}</a-descriptions-item>
    <a-descriptions-item label="密码">{{
      info[0] && info[0].m_pwd
    }}</a-descriptions-item>
    <a-descriptions-item label="状态">{{ names }}</a-descriptions-item>
  </a-descriptions>
  <!-- 操作按钮 -->
  <a-button type="primary" @click="openUpd">修改管理员信息</a-button>

  <!-- 弹窗 -->
  <a-modal v-model:visible="visible" title="修改管理员信息" @ok="execUpd">
    <a-form
      :model="updObj"
      :label-col="{ span: 5 }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-item label="管理员ID">
        <a-input v-model:value="updObj.m_id" disabled />
      </a-form-item>
      <a-form-item label="状态">
        <a-input v-model:value="updObj.m_status" disabled />
      </a-form-item>
      <a-form-item label="昵称">
        <a-input v-model:value="updObj.m_name" />
      </a-form-item>
      <a-form-item label="性别">
        <a-input v-model:value="updObj.m_sex" />
      </a-form-item>
      <a-form-item label="生日">
        <a-input v-model:value="updObj.m_birth" />
      </a-form-item>
      <a-form-item label="密码">
        <a-input v-model:value="updObj.m_pwd" />
      </a-form-item>
      <a-form-item :wrapper-col="{ span: 14, offset: 4 }"> </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup>
import { ref, reactive } from "vue";
import { get, put, tip } from "@/common";
const info = ref([]);
const getInfo = () => {
  get("/admin/a_info").then((res) => {
    info.value = res.data.list;
    name();
  });
};
getInfo();

// 修改操作
const updObj = reactive({
  m_id: "",
  m_name: "",
  m_sex: "",
  m_birth: "",
  m_status: "",
  m_pwd: "",
});
const visible = ref(false);
const openUpd = () => {
  updObj.m_id = info.value[0].m_id; //js里要加.value
  updObj.m_name = info.value[0].m_name;
  updObj.m_sex = info.value[0].m_sex == "1" ? "男" : "女";
  updObj.m_birth = info.value[0].m_birth;
  updObj.m_pwd = info.value[0].m_pwd;
  updObj.m_status = info.value[0].m_status;
  visible.value = true;
  console.log(updObj);
};
const execUpd = () => {
  put("/admin/a_info", updObj).then((res) => {
    updObj.m_id = "";
    updObj.m_name = "";
    updObj.m_sex = "";
    updObj.m_birth = "";
    updObj.m_status = "";
    updObj.m_pwd = "";
    visible.value = false;
    tip.success("修改成功");
    getInfo();
  });
};
var names = ref("");

const name = () => {
  if (info.value[0].m_status == "c_admin") names.value = "电影院管理员";
  else names.value = "平台管理员";
};
</script>